package com.gable.exhibition.service.impl;

import com.gable.common.util.ReturnResultUtil;
import com.gable.exhibition.dao.TrainFileDao;
import com.gable.exhibition.service.TrainFileService;
import com.gable.exhibition.util.MessageUtil;
import com.gable.exhibition.view.TrainFileView;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by SJX on 2018/3/6.
 */
@Service("trainFileService")
public class TrainFileServiceImpl implements TrainFileService {

    Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    TrainFileDao trainFileDao;

    @Override
    public ReturnResultUtil queryTrainFile(TrainFileView trainFileView) {
        List<TrainFileView> list = trainFileDao.queryTrainList(trainFileView);
        return new ReturnResultUtil(200, MessageUtil.QUERYSUCCESS,list);
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public ReturnResultUtil addTrainFile(List<TrainFileView> trainFileViews) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for(TrainFileView trainFileView:trainFileViews){
            trainFileView.setCreateDate(df.format(new Date()));
            trainFileView.setIsDel(0);
            trainFileDao.insertSelective(trainFileView);
        }
        return new ReturnResultUtil(200, MessageUtil.SAVESUCCESS,trainFileViews);
    }
}
